// JavaScript Document
var xmlDoc="";
var call_id=""; //通话唯一标识；
var charnum=new Array();
function call(callarr){
   var obj=document.getElementsByName(callarr);
   var leng=obj.length;
   var phone_book="";
   for(var i=0;i<leng;++i){
	   if(obj.item(i).checked==true){
		   phone_book+=","+obj.item(i).value;
		   }
	   }
if(phone_book==""){alert("没有选择打电话用户");return 0;}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=convokeMeeting&phoneNo="+phone_book,
			success:function(data){
				if(typeof(data)=="undefined"){
					alert("还没有开通这个业务");
					}else{
				var data_arr=data.split(",");
				if(data_arr[0]!='100'){
					alert("没有拨打成功");
					}else{
				call_id=data_arr[1];}
			}}
		});

	}
	
function stop_call(){
	if(call_id==""){
		alert("没有在通话");
		return 0;
		}		
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=endMeeting&number="+call_id,
			success:function(data){
			if(data!='100'){
				alert("没有结束对话");
				}else{
			call_id="";
			}	
			}
		});
	}
	
	
function post_message(chebox,text){
   var obj=document.getElementsByName(chebox);
   var leng=obj.length;
   var phone_book="";
   for(var i=0;i<leng;++i){
	   if(obj.item(i).checked==true){
		   phone_book+=","+obj.item(i).value;
		   }
	   }
if(phone_book==""){alert("没有选择打电话用户");return 0;}
if(document.getElementById(text).value==""){
	alert("没有输入要发送的信息");return 0;
	}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/msg.php",
			cache:false,
			data:"phoneNo="+phone_book+"&msg="+document.getElementById(text).value,
			success:function(data){
				if(data==1){
					document.getElementById('msg').innerHTML="<span style='color:#06F'>发送成功</span>";
					}else{
						if(data==2){
							document.getElementById('msg').innerHTML="<span style='color:#F00'>查看输入是否正确</span>";
							}else{
					  document.getElementById('msg').innerHTML="<span style='color:#F00'>发送失败</span>";}
			}}
		});

	return 0;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	function call_one(callarr){
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=convokeMeeting&phoneNo="+callarr,
			success:function(data){
				if(typeof(data)=="undefined"){
					alert("还没有开通这个业务");
					}else{
				var data_arr=data.split(",");
				if(data_arr[0]!='100'){
					alert("没有拨打成功");
					}else{
				call_id=data_arr[1];}
			}}
		});

	}
	
function stop_call_one(){
	if(call_id==""){
		alert("没有在通话");
		return 0;
		}
		
		$.ajax({
			type:"POST",
			url:"public/talk.php",
			cache:false,
			data:"act=endMeeting&number="+call_id,
			success:function(data){
			if(data!='100'){
				alert("没有结束对话");
				}else{
			call_id="";
			}	
			}
		});
	}
	
	
	
	
function post_message_one(chebox,text){
	   var phone_book=chebox;
if(phone_book==""){alert("没有选择打电话用户");return 0;}
if(document.getElementById(text).value==""){
	alert("没有输入要发送的信息");return 0;
	}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/msg.php",
			cache:false,
			data:"phoneNo="+phone_book+"&msg="+document.getElementById(text).value,
			success:function(data){
				if(data==1){
					document.getElementById('msg').innerHTML="<span style='color:#06F'>发送成功</span>";
					}else{
						if(data==2){
							document.getElementById('msg').innerHTML="<span style='color:#F00'>查看输入是否正确</span>";
							}else{
					  document.getElementById('msg').innerHTML="<span style='color:#F00'>发送失败</span>";}
			}}
		});

	return 0;
	}
function post_message_one_1(chebox,text){
	   var phone_book=chebox;
if(phone_book==""){alert("没有选择打电话用户");return 0;}
if(document.getElementById(text).value==""){
	alert("没有输入要发送的信息");return 0;
	}
phone_book=phone_book.substr(1,phone_book.length-1);
		$.ajax({
			type:"POST",
			url:"public/msg.php",
			cache:false,
			data:"phoneNo="+phone_book+"&msg="+document.getElementById(text).value,
			success:function(data){
				if(data==1){
					document.getElementById('message_m').innerHTML="<span style='color:#06F'>发送成功</span>";
					}else{
						if(data==2){
							document.getElementById('message_m').innerHTML="<span style='color:#F00'>查看输入是否正确</span>";
							}else{
					  document.getElementById('message_m').innerHTML="<span style='color:#F00'>发送失败</span>";}
			}}
		});

	return 0;
	}




function textarea_is(obj){
	if(obj.value.length>60){
		obj.value=obj.value.substr(0,60);
		alert("长度超出60字符");
		}
	}






function SOS(){
	prompt_1();
	function prompt_1(){
        if(window.XMLHttpRequest) {                                                         //Mozilla浏览器
            xmlHttp=new XMLHttpRequest();
                if(xmlHttp.overrideMimeType) {                                                  //设置MIME类别
                   xmlHttp.overrideMimeType("text/xml");
                }
            } else if(window.ActiveXObject) {                                                   //IE浏览器
                try {
                    xmlHttp=new ActiveXObject("Msxml2.XMLHttp");
                }
                catch(e) {
                    try {
                        xmlHttp=new ActiveXobject("Microsoft.XMLHttp");
                    }
                    catch(e){
                    }
                }
                }
		 var url="js/SOS.php";
		 xmlHttp.onreadystatechange=handle_f;
		 xmlHttp.open("GET",url,true);
		 xmlHttp.send(null);
		}
	function handle_f(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.status==200){
				xmlDoc=xmlHttp.responseText;
				if(typeof(xmlDoc)=='undefined'){
					return 0;
					}
						if(xmlDoc!=''){
						   document.getElementById('SOS').getElementsByTagName("span").item(0).style.color="#FF0000";
						   document.getElementById('SOS').getElementsByTagName("a").item(0).style.color="#FF0000";
						   if(!+[1,])
						   document.getElementById('mplay').play();		
						   if(document.getElementById("msg_win").style.display != 'block'){
							   var str="";
							   if(!xmlDoc||xmlDoc==""){str="<span style='color:#F00'>没有报警数据</span>";}else{
							   str='<div>部门：'+xmlDoc.split("_")[2]+"</br>车牌："+xmlDoc.split("_")[3]+"</br>时间："+xmlDoc.split("_")[4]+"</br>经度："+xmlDoc.split("_")[5]+"</br>纬度："+xmlDoc.split("_")[6]+"</br>手机号："+xmlDoc.split("_")[7]+'</div><textarea  onkeyup="textarea_is(this)" id="textarea_post_one_index" ></textarea></br><input "+str1+" type="button" onclick="post_message_one_1(\''+xmlDoc.split("_")[7]+',\',\'textarea_post_one_index\')" class="btnbg" style="width:70px;" value="发送消息"  /><input type="button" "+str1+" onclick="call_one(\''+xmlDoc.split("_")[7]+'\')" class="btnbg" style="width:70px;" value="发送语音" /><input type="button" "+str1+"  onclick="stop_call()" class="btnbg" style="width:70px;" value="挂断" /></br><div id="message_m"></div>';
							   }
							   document.getElementById("msg_content").innerHTML=str;
							   Message_box.init();
							   }
						
							}
			          }
								  else{
				                   alert("执行出现问题"+xmlHttp.statusText);
								   }
				}
				}
	setTimeout(SOS,10000);
	}
//setTimeout(SOS,1000);
		
function c(){
			$.ajax({
			type:"POST",
			url:"public/listen.php",
			cache:false,
			data:"option=c",
			success:function(data){
				if(typeof(data)=='undefined'){
					return 0;
					}
						if(data!='N'){
						   document.getElementById('Location').getElementsByTagName("span").item(0).style.color="#FF0000";
						   document.getElementById('Location').getElementsByTagName("a").item(3).style.color="#FF0000";
						   charnum=[];
						   charnum.push(data.split('_')[0]);
						   charnum.push(data.split('_')[1]);
				}
				setTimeout(c,10000);
			}
		});
	}
//setTimeout(c,1000);

function QueryInfoStop(){
			$.ajax({
			type:"POST",
			url:"public/listen.php",
			cache:false,
			data:"option=c&a="+charnum[0],
			success:function(data){
				if(typeof(data)=='undefined'){
					return 0;
					}
						if(data!='N'){
            	 charnum=[];
						   document.getElementById('Location').getElementsByTagName("span").item(0).style.color="#666";
						   document.getElementById('Location').getElementsByTagName("a").item(3).style.color="#666";
						alert("停止成功");
						}else{
							alert("停止失败");
							}
				}
		});
}


















var Message_box={
set: function() {//最小化与恢复状态切换
var set=this.minbtn.status == 1?[0,1,'block',this.char[0],'最小化']:[1,0,'none',this.char[1],'恢复'];
this.minbtn.status=set[0];
this.win.style.borderBottomWidth=set[1];
this.content.style.display =set[2];
this.minbtn.innerHTML =set[3]
this.minbtn.title = set[4];
this.win.style.top = this.getY().top;
},
close: function() {//关闭
this.win.style.display = 'none';
window.onscroll = null;
},
setOpacity: function(x) {//设置透明度
var v = x >= 100 ? '': 'Alpha(opacity=' + x + ')';
this.win.style.visibility = x<=0?'hidden':'visible';//IE有绝对或相对定位内容不随父透明度变化的bug
this.win.style.filter = v;
this.win.style.opacity = x / 100;
},
show: function() {//渐显
clearInterval(this.timer2);
var me = this,fx = this.fx(0, 100, 0.1),t = 0;
this.timer2 = setInterval(function() {
t = fx();
me.setOpacity(t[0]);
if (t[1] == 0) {clearInterval(me.timer2) }
},10);
},
fx: function(a, b, c) {//缓冲计算
var cMath = Math[(a - b) > 0 ? "floor": "ceil"],c = c || 0.1;
return function() {return [a += cMath((b - a) * c), a - b]}
},
getY: function() {//计算移动坐标
var d = document,b = document.body, e = document.documentElement;
var s = Math.max(b.scrollTop, e.scrollTop);
var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
var h2 = this.win.offsetHeight;
return {foot: s + h + h2 + 2+'px',top: s + h - h2 - 2+'px'}
},
moveTo: function(y) {//移动动画
clearInterval(this.timer);
var me = this,a = parseInt(this.win.style.top)||0;
var fx = this.fx(a, parseInt(y));
var t = 0 ;
this.timer = setInterval(function() {
t = fx();
me.win.style.top = t[0]+'px';
if (t[1] == 0) {
clearInterval(me.timer);
me.bind();
}
},10);
},
bind:function (){//绑定窗口滚动条与大小变化事件
var me=this,st,rt;
window.onscroll = function() {
clearTimeout(st);
clearTimeout(me.timer2);
me.setOpacity(0);
st = setTimeout(function() {
me.win.style.top = me.getY().top;
me.show();
},600);
};
window.onresize = function (){
clearTimeout(rt);
rt = setTimeout(function() {me.win.style.top = me.getY().top},100);
}
},
init: function() {//创建HTML
function $(id) {return document.getElementById(id)};
this.win=$('msg_win');
var set={minbtn: 'msg_min',closebtn: 'msg_close',title: 'msg_title',content: 'msg_content'};
for (var Id in set) {this[Id] = $(set[Id])};
var me = this;
this.minbtn.onclick = function() {me.set();this.blur()};
this.closebtn.onclick = function() {me.close()};
this.char=navigator.userAgent.toLowerCase().indexOf('firefox')+1?['_','::','×']:['0','2','r'];//FF不支持webdings字体
this.minbtn.innerHTML=this.char[0];
this.closebtn.innerHTML=this.char[2];
setTimeout(function() {//初始化最先位置
me.win.style.display = 'block';
me.win.style.top = me.getY().foot;
me.moveTo(me.getY().top);
},0);
return this;
}
};